home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / hook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-02  |  2.4 KB  |  107 lines

  1. #ifndef XPKMASTER_HOOK_C
  2. #define XPKMASTER_HOOK_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        hook.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: hook.c 1.1 (27.12.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Hook handling functions
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   27.12.96 : removed V37 defines
  15. */
  16.  
  17. #include <exec/types.h>
  18. #include "xpkmaster.h"
  19.  
  20. typedef ULONG __asm (*regfunc) (register __a0 struct Hook *,
  21.             register __a1 APTR,
  22.             register __a2 APTR
  23. #ifdef SUPPORT_A4
  24.             ,register __a4 ULONG
  25. #endif
  26.             );
  27.  
  28. ULONG __asm MyCallHookPkt(register __a0 struct Hook *hook,
  29. register __a1 APTR paramPacket A4PROTO)
  30. {
  31.   if(!hook)
  32.     return 0;
  33.  
  34.   return (*(regfunc) hook->h_Entry) (hook, paramPacket, NULL A4SUPP);
  35. }
  36.  
  37. #ifdef DEBUG
  38. static STRPTR action_names[8] =
  39. {"<zero>", "XIO_READ", "XIO_WRITE", "XIO_FREE", "XIO_ABORT", "XIO_GETBUF",
  40. "XIO_SEEK", "XIO_TOTSIZE" };
  41. #endif
  42.  
  43. /*************************** read from input hook ************************/
  44.  
  45. APTR hookread(struct XpkBuffer *xbuf, ULONG action, APTR buf, ULONG size)
  46. {
  47.   LONG res;
  48.  
  49.   xbuf->xb_RMsg.xmm_Type = action;
  50.   xbuf->xb_RMsg.xmm_Ptr = (STRPTR) buf;
  51.   xbuf->xb_RMsg.xmm_Size = size;
  52.  
  53.   if((res = MyCallHookPkt(xbuf->xb_RHook, &xbuf->xb_RMsg A4SUPP2)))
  54.   {
  55. //   xbuf->xb_Result2 = xbuf->xb_RMsg.xmm_IOError;
  56.      xbuf->xb_Result = res;
  57.   }
  58.  
  59.   if(xbuf->xb_Result)
  60.   {
  61. #ifdef DEBUG
  62.     DebugError("hookread: %s <%ld> (%ld)", action_names[(action&7)], action,
  63.     xbuf->xb_Result);
  64. #endif
  65.     return NULL;
  66.   }
  67.   else if(xbuf->xb_RMsg.xmm_Ptr)
  68.     return (APTR) xbuf->xb_RMsg.xmm_Ptr;
  69.   else
  70.     return (APTR) -1;    /* SEEK may return 0 an success! */
  71. }
  72.  
  73.  
  74. /*************************** write to output hook ************************/
  75.  
  76. APTR hookwrite(struct XpkBuffer *xbuf, ULONG action, APTR buf, ULONG size)
  77. {
  78.   LONG res;
  79.  
  80.   xbuf->xb_WMsg.xmm_Type = action;
  81.   xbuf->xb_WMsg.xmm_Ptr = (STRPTR) buf;
  82.   xbuf->xb_WMsg.xmm_Size = size;
  83.  
  84.   if((res = MyCallHookPkt(xbuf->xb_WHook, &xbuf->xb_WMsg A4SUPP2)))
  85.   {
  86.     xbuf->xb_Result = res;
  87. //  xbuf->xb_Result2 = xbuf->xb_WMsg.xmm_IOError;
  88.   }
  89.   else if(action == XIO_WRITE)
  90.     xbuf->xb_OutLen += size;
  91.  
  92.   if(xbuf->xb_Result)
  93.   {
  94. #ifdef DEBUG
  95.     DebugError("hookwrite: %s <%ld> (%ld)", action_names[(action&7)], action,
  96.     xbuf->xb_Result);
  97. #endif
  98.     return NULL;
  99.   }
  100.   else if(xbuf->xb_WMsg.xmm_Ptr)
  101.     return (APTR) xbuf->xb_WMsg.xmm_Ptr;
  102.   else
  103.     return (APTR) -1; /* SEEK may return 0 an success! */
  104. }
  105.  
  106. #endif /* XPKMASTER_HOOK_C */
  107.